/**
 * 
 */
package com.youth.fund.hk.hostManager.manager.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.youth.fund.hk.hostManager.manager.datamodel.NewsModel;
import com.youth.fund.hk.hostManager.manager.service.NewsService;

/**
 * @author Sunk_Sky
 *
 *         2014年11月27日下午3:06:56
 */
@Controller
@RequestMapping("/json/news")
public class NewsWebServiceController
{
	@Autowired
	@Qualifier("NewsService")
	private NewsService service;

	@RequestMapping(value = "/table.json")
	@ResponseBody
	public List searchNews(
			@RequestParam(required = false, defaultValue = "") String keyword,
			@RequestParam(required = false, defaultValue = "1") int pageIndex,
			@RequestParam(required = false, defaultValue = "10") int pageSize,
			@RequestParam(required = false, defaultValue = "zh_hk") String lang,
			@RequestParam(required = false, defaultValue = "market_comments") String code
			)
	{
		
		PageBounds bound = new PageBounds(pageIndex, pageSize,
				Order.formString("id.desc"));

		NewsModel model = new NewsModel();

		model.setName(keyword);
		//目前所有的搜索都搜繁体中文，不提供不同语言的东西全球的上传
		model.setName(lang);
		
		model.setCode(code);

		return service.searchPage(model, bound);
	}
}
